package com.yuanluludev.lib_x5web

import android.content.Context
import android.content.Intent
import android.text.TextUtils
import com.tencent.smtt.sdk.QbSdk
import com.yuanluludev.lib_base.base.BaseActivity
import com.yuanluludev.lib_utils.util.LogUtils
import kotlinx.android.synthetic.main.activity_file_read.*

/**
 * yuanLulu
 * 文档阅读
 */
class FileReadActivity : BaseActivity() {

    companion object {
        private const val FILE_PATH = "file_path"
        private const val TITLE_TEXT = "title_text"

        @JvmStatic
        fun jump(context: Context, filePath: String, titleText: String = "") {
            context.startActivity(Intent(context, FileReadActivity::class.java).apply {
                putExtra(FILE_PATH, filePath)
                putExtra(TITLE_TEXT, titleText)
            })
        }
    }

    override fun getLayoutResId() = R.layout.activity_file_read

    override fun initEvents() {
        val titleText = intent?.getStringExtra(TITLE_TEXT) ?: ""
        val filePath = intent?.getStringExtra(FILE_PATH) ?: ""
        if (!TextUtils.isEmpty(titleText)) {
            titleBar?.setTitleText(titleText)
        }
        if (!TextUtils.isEmpty(filePath)) {
            fileReadView?.show(filePath)
        }
        LogUtils.d("X5WebInit","内核版本号 = ${QbSdk.getTbsVersion(this)}")
    }

    override fun onDestroy() {
        fileReadView?.stop()
        super.onDestroy()
    }

}